.org 0xE61D8 ; Defense Increase (Direct & Indirect)

Defense_Increase_Direct_Indirect:

	PUSH 	{R4-R6, LR}
		
	MOV		R5, 0								; Defense bonus = 0
	
;-------------------------------------------------------------------------------
	
	MOV		R6, R0
	MOV		R0, R2								; R0 = Unit
	
	BL 		Check_Unit_Type
	
	CMP		R0, Unit_Direct_Combat				; Is Unit a Direct?
	BEQ		Skill_Defense_Direct
	
	CMP		R0, Unit_Indirect_Combat			; Is Unit an Indirect?
	BEQ		Skill_Defense_Indirect
	
	B		CO_Defense_SCOP

;-------------------------------------------------------------------------------	

Skill_Defense_Direct:

	BL		Skill_Setup_Type_Defense_1
		
	MOV		R1, Rank_Slam_Guard					; Rank: Slam Guard	
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped	
	CMP 	R0, 0								; Does CO use that skill?	
	ADDNE 	R5, R5, Stats_Slam_Guard			; If CO use skill, more Direct defense	
	
;-------------------------------------------------------------------------------
	
	BL		Skill_Setup_Type_Defense_2
	
	MOV 	R1, Rank_Slam_Shield				; Rank: Slam Shield
		
	BL 		Check_Skills_Equipped				; Check the Skill is equipped	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R5, R5, Stats_Slam_Shield			; If CO use skill, more Direct defense
	
	B		CO_Defense_SCOP

;-------------------------------------------------------------------------------	

Skill_Defense_Indirect:

	BL		Skill_Setup_Type_Defense_1
	
	MOV		R1, Rank_Snipe_Guard				; Rank: Snipe Guard		
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R5, R5, Stats_Snipe_Guard			; If CO use skill, more Indirect defense	
		
;-------------------------------------------------------------------------------
	
	BL		Skill_Setup_Type_Defense_2
	
	MOV		R1, Rank_Snipe_Shield				; Rank: Snipe Shield
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R5, R5, Stats_Snipe_Shield			; If CO use skill, more Indirect defense
	
;-------------------------------------------------------------------------------	
	
	BL		Skill_Power_Check
	
	CMP		R0, Power_None						; No powers activated?
	BNE		CO_Defense_D2D
	
	BL		Skill_Setup_Type_Defense_2
	
	MOV		R1, CO_Indirect_Defense				; Skill: Indirect Defense 1
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R5, R5, Stats_Indirect_Defense_D2D	; If CO use skill, +20 Indirect defense

CO_Defense_D2D:
	
;-------------------------------------------------------------------------------	
	
	BL		Skill_Power_Check
	
	CMP		R0, Power_COP						; Has COP been activated?
	BNE		CO_Defense_COP
	
	BL		Skill_Setup_Type_Defense_2
	
	MOV		R1, CO_Indirect_Defense				; Skill: Indirect Defense 2
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R5, R5, Stats_Indirect_Defense_COP	; If CO use skill, +40 Indirect defense

CO_Defense_COP:
	
;-------------------------------------------------------------------------------	
	
	BL		Skill_Power_Check
	
	CMP		R0, Power_SCOP						; Has SCOP been activated?
	BNE		CO_Defense_SCOP
	
	BL		Skill_Setup_Type_Defense_2
	
	MOV		R1, CO_Indirect_Defense				; Skill: Indirect Defense 3
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R5, R5, Stats_Indirect_Defense_SCOP	; If CO use skill, +60 Indirect defense

CO_Defense_SCOP:

;-------------------------------------------------------------------------------	
		
	MOV		R0, R5								; Total defense bonus
	
	POP 	{R4-R6, LR}	
	BX 		LR
	
;-------------------------------------------------------------------------------

Skill_Setup_Type_Defense_1:						; Defense Setup 1

	LDR 	R1, [Defense_Increase_Direct_Indirect_1]
	LDR 	R0, [Defense_Increase_Direct_Indirect_2]
	LDR 	R2, [R1, 0]
	LDR 	R1, [R0, 0]
	
	MOV 	R0, 0x98	
	ADD		R1, R2, R1, LSL 2
	MUL 	R4, R6, R0
	LDR 	R1, [R1, 0x48]	
	ADD 	R0, R1, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD		R0, R0, R4
	ADD 	R0, R0, 0x74
	
	BX 		LR
	
;-------------------------------------------------------------------------------

Skill_Setup_Type_Defense_2:						; Defense Setup 2

	LDR 	R1, [Defense_Increase_Direct_Indirect_1]
	LDR 	R0, [Defense_Increase_Direct_Indirect_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	ADD		R0, R2, R0, LSL 2
	LDR		R0, [R0, 0x48]
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD 	R0, R0, R4
	ADD 	R0, R0, 0x74
	
	BX 		LR

;-------------------------------------------------------------------------------	

Skill_Setup_Type_Defense_Weather:				; Defense Weather Setup

	ADD 	R0, R1, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R4
	
	BX 		LR

;-------------------------------------------------------------------------------

Skill_Setup_Type_Defense_Transport:				; Transport Defense Setup

	LDR 	R1, [Defense_Increase_Tag_Transport_1]
	LDR 	R0, [Defense_Increase_Tag_Transport_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
		
	ADD		R0, R2, R0, LSL 2
	LDR		R0, [R0, 0x48]	
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R4
	
	BX 		LR

;-------------------------------------------------------------------------------
	
	NOP	
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP	
	
;-------------------------------------------------------------------------------	

Defense_Increase_Direct_Indirect_1:
	.dw Reg1_Skill
	
Defense_Increase_Direct_Indirect_2:
	.dw Reg2_Skill



